package en.edu.zucc.pb.loginapplication;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.TypeConverters;

import en.edu.zucc.pb.loginapplication.dao.BaseDao;
import en.edu.zucc.pb.loginapplication.dao.RecordDao;
import en.edu.zucc.pb.loginapplication.dao.UserDao;
import en.edu.zucc.pb.loginapplication.entity.Record;
import en.edu.zucc.pb.loginapplication.entity.User;

//import en.edu.zucc.pb.room.dao.AuthorDao;
//import en.edu.zucc.pb.room.dao.BookDao;
//import en.edu.zucc.pb.room.entity.Author;
//import en.edu.zucc.pb.room.entity.Book;

//1
@Database(entities = {User.class, Record.class}, version = 2, exportSchema = false)
@TypeConverters({RoomConverter.class})
public abstract class AppDatabase extends RoomDatabase {
    //    public abstract AuthorDao authorDao();
    private static final String DATABASE_NAME = "";
//    public abstract UserDao userDao();
//    确实 这会 生成代码
//    public abstract BookDao bookDao();

    /**
     * 获取AlarmClockDao对象
     *
     * @return AlarmClockDao对象
     */
//    public abstract UserDao getUserDao();
//
//    public abstract RecordDao getRecordDao();
//    public abstract BaseDao getBaseDao();

    public abstract UserDao userDao();

    public abstract RecordDao recordDao();

    private static volatile AppDatabase INSTANCE;

    public static AppDatabase getDatabase(Context context) {
        if (INSTANCE == null) {
            synchronized (AppDatabase.class) {
                if (INSTANCE == null) {
//                    "alarm_clock" 这个是储存的文件的名字吧 databases里面的
                    String dbFileName = "login.db";
//                    String  dbFileName="alarm_clock";
                    INSTANCE = Room.databaseBuilder(context, AppDatabase.class, dbFileName)
//                            .allowMainThreadQueries()
//                            .addMigrations(MIGRATION_1_2)
//                    https://blog.csdn.net/u013762572/article/details/106315045
                            .fallbackToDestructiveMigration()
                            .build();
                }
            }
        }
        return INSTANCE;
    }
}
